package cn.sangkf.litemall.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.HttpAsyncResponseConsumerFactory;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author : sangkf
 * @package : cn.sangkf.litemall.search.config.ElasticSearchConfig
 * @date : 2020/12/28 下午10:22 星期一
 * @description : TODO ElasticSearch配置
 * @version: 1.0
 * <p>Copyright: Copyright (c) 2020</p>
 */
@Configuration
public class ElasticSearchConfig {

    public static final RequestOptions COMMON_OPTIONS;

    /**
     * elastic请求option设置
     */
    static {
        RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
//        builder.addHeader("Authorization", "Bear " + "token");
//        builder.setHttpAsyncResponseConsumerFactory(new
//                HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory(30 * 1024 * 1024 * 1024));
        COMMON_OPTIONS = builder.build();
    }


    @Bean
    public RestHighLevelClient restHighLevelClient() {
        return new RestHighLevelClient(RestClient.builder(new HttpHost("127.0.0.1", 9201)));
    }

}
